import axios from 'axios'
import { store } from '../store'
import { baseURL } from '@/constants'

// 创建axios实列
const service = axios.create({
  baseURL
})

// 响应拦截
service.interceptors.response.use(res => {
  if (res.status === 200) {
    const resData = res.data
    if (resData.code === 200) {
      return Promise.resolve(resData)
    }
  } else {
    const err = new Error('从后端的返回的数据code不为200')
    err.error = res.data
    return Promise.reject(err)
  }
})
export default service